package com.zhangjh.web.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.zhangjh.web.filter.TiemFliter;
import com.zhangjh.web.interceptor.TimeIntercepor;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{
	@Autowired
	private TimeIntercepor timeIntercepor;
	
	@Override
	public void addInterceptors(InterceptorRegistry timeIntercepor) {
		super.addInterceptors(timeIntercepor);
	}
	
	@Bean
	public FilterRegistrationBean filterRegistrationBean(){
		FilterRegistrationBean bean =new FilterRegistrationBean();
		//添加自定义过滤器
		TiemFliter fliter = new TiemFliter();
		bean.setFilter(fliter);
		//添加过滤路径
		List<String> urls = new ArrayList<>();
		urls.add("/*");
		bean.setUrlPatterns(urls);
		return bean;
	}
}
